package com.zjd.association.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zjd.association.common.PageWrapper;
import com.zjd.association.entity.PayLogs;
import com.zjd.association.mapper.PayLogsMapper;
import com.zjd.association.service.PayLogsService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 缴费记录 服务层实现类
 *
 * @author: zjd
 * @date: 2024-5-22
 */
@Service
@RequiredArgsConstructor
public class PayLogsServiceImpl implements PayLogsService {

    private final PayLogsMapper payLogsMapper;

    @Override
    public void add(PayLogs payLogs) {
        payLogsMapper.insert(payLogs);
    }

    @Override
    public void update(PayLogs payLogs) {
        payLogsMapper.updateById(payLogs);
    }

    @Override
    public void delete(PayLogs payLogs) {
        payLogsMapper.deleteById(payLogs);
    }

    @Override
    public PayLogs getOne(String id) {
        PayLogs payLogs = payLogsMapper.selectById(id);
        return payLogs;
    }

    /**
     * 团队管理员分页查询缴费记录信息
     *
     * @param pageIndex 当前页码
     * @param pageSize  每页数据量
     * @param userId    用户编号
     * @param teamName  团队名称
     * @param userName  用户姓名
     * @return 付款记录
     */
    @Override
    public PageWrapper getManPageInfo(Long pageIndex, Long pageSize, String userId, String teamName, String userName) {
        Page<Map<String, Object>> page =
                payLogsMapper.qryManPageInfo(new Page<>(pageIndex, pageSize), userId, teamName, userName);

        return parsePage(page);
    }

    /**
     * 分页查询缴费记录信息
     *
     * @param pageIndex 当前页码
     * @param pageSize  每页数据量
     * @param userId    用户编号
     * @param teamName  团队名称
     * @param userName  用户姓名
     * @return 付款记录
     */
    @Override
    public PageWrapper getPageInfo(Long pageIndex, Long pageSize, String userId, String teamName, String userName) {
        Page<Map<String, Object>> page =
                payLogsMapper.qryPageInfo(new Page<>(pageIndex, pageSize), userId, teamName, userName);

        return parsePage(page);
    }

    /**
     * 分页转换
     *
     * @param p 分页对象
     * @return 分页保证
     */
    public PageWrapper parsePage(Page<Map<String, Object>> p) {
        PageWrapper pageWrapper = new PageWrapper(p.getCurrent(), p.getSize(), p.getTotal(), p.getRecords());
        return pageWrapper;
    }
}